package thread;

import java.util.concurrent.Semaphore;

public class ThreadDemo37 {
    public static void main(String[] args) throws InterruptedException {
        Semaphore semaphore = new Semaphore(1);
        //p获取资源, v释放资源
        semaphore.acquire();
        System.out.println("p操作1");
        semaphore.release();
        System.out.println("v操作1");
        semaphore.acquire();
        System.out.println("p操作2");
        semaphore.release();
        System.out.println("v操作2");
        semaphore.acquire();
        System.out.println("p操作3");
        semaphore.release();
        System.out.println("v操作3");
        semaphore.acquire();
        System.out.println("p操作4");
        semaphore.release();
        System.out.println("v操作1");


    }
}
